using Gee;
using SQLHeavy;
using Meridian.Data;

namespace Meridian.Side.Recovery {

public abstract class RecoveryFactory<S> : GLib.Object {

    public Dao dao {construct; private get;}
    
    public RecoveryFactory (Dao dao) {
        GLib.Object(dao : dao);
    }

    public Gee.List<S> recover () {   
        var records = this.dao.select_records (get_table (), get_order ());
		var items = new ArrayList<S> ();
    	
    	while (!records.finished) {
	    	records.next ();
        	items.add (create_item (records));        	
    	}
        
        return items;
    }
    
    protected DateTime to_date (int64 timestamp) {
	    return new DateTime.from_unix_local (timestamp);
    }
    
    protected abstract S create_item (QueryResult records);
    
    protected abstract Gee.List<DataOrder> get_order ();
    
    protected abstract DataTable get_table ();
    
}
}